<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #title span{
            margin-right: 33px;
            display: inline-block;
        }
        #content {
            width: 100px;
            height: 100px;
            border: 1px solid orchid;
            position: relative;
        }
        #content div {
            width: 100%;
            height: 100%;
            position: absolute;
        }
        #content div:first-child{
            background-color: palegreen;
           
        }
        #content div:last-child{
            background-color: orangered;
            display: none;
        }
        .active{
            color: orangered;
        }
    </style>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>
<body>
    <div id="title">
        <span class="active">登录</span> 
        <span>注册</span>
    </div>
    <div id="content">
        <div>登录内容</div>
        <div>注册内容</div>
    </div>
    <script>
        $("#title span").click(function(){
            $(this).addClass('active').siblings().removeClass('active');
            var index = $(this).index();
            $("#content div").eq(index).show().siblings().hide();
        })

    </script>
</body>
</html>